//import leave from "@/views/_mixins/leave";
//mixins: [leave],
export default {
  mounted() {
    window.addEventListener("beforeunload", this.beforeUnloadHandler, false);
  },
  destroyed() {
    window.removeEventListener("beforeunload", this.beforeUnloadHandler, false);
  },
  methods: {
    beforeUnloadHandler(e) {
      e.returnValue = "离开此页面？"; // 此处返回任意字符串，不返回null即可，不能修改默认提示内容
    },
    leaveConfirm() {
      return this.$confirm(
        `离开当前页面不会保存已填写内容，是否离开？`,
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          cancelButtonClass: 'cancel-msgbtn', confirmButtonClass: 'confirm-msgbtn', type: 'warning',
        }
      )
        .then(() => true)
        .catch(() => false);
    },
    async btnLeave() {
      let res = await this.leaveConfirm();
      if (!res) return;
      this.$router.back();
    },
  },
};
